﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Moe_v0._1
{
    class MoeAnswer
    {
        private int _previousIndex = 0;
        private List<string> _answerList = new List<string>();
        private static Random rand = new Random(System.DateTime.Today.Millisecond);
        private static List<string> _noAnswers = new List<string>();

        public MoeAnswer() {}
        
        public MoeAnswer(params string[] answers)
        {
            foreach (string answer in answers)
            {
                _answerList.Add(answer);
            }
        }

        public void AddAnswer(string answer)
        {
            _answerList.Add(answer);
        }
        public string SelectAnswer()
        {
            Debug.Assert(_answerList.Count > 0);

            if (MoeDebugger.IsDebugging)
            {
                MoeDebugger.AddDebugInfo("===MoeAnswer::SelectAnswer===");
                MoeDebugger.AddDebugInfo(string.Format("previous answer index is: {0}."
                    , _previousIndex));
                MoeDebugger.AddDebugInfo("-----------------------------");
            }
            int currentIndex = 0;
            if (_answerList.Count > 1 && currentIndex == _previousIndex)
            {
                while (currentIndex == _previousIndex)
                {
                    currentIndex = rand.Next(_answerList.Count);
                }
            }
            _previousIndex = currentIndex;
            return _answerList[currentIndex];
        }
        public void ClearAllAnswer()
        {
            Debug.Assert(_answerList != null);
            _answerList.Clear();
        }

        public static string GetNegativeAnswer()
        {
            if (_noAnswers.Count == 0)
            {
                _noAnswers.Add("Sorry, I don't understand.");
                _noAnswers.Add("Er...");
                _noAnswers.Add("Pardon?");
                _noAnswers.Add("I want to talk about other things.");
                _noAnswers.Add("Well, maybe?");
                _noAnswers.Add("You think so?");
                _noAnswers.Add("...");
                _noAnswers.Add("Somtimes, I suppose...Er...well, I don't know.");
                _noAnswers.Add("Why not ask my creator?");
                _noAnswers.Add("I am a robot, so...You know it.");
            }
            return _noAnswers[rand.Next(0, _noAnswers.Count)];
        }
    }
}
